﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using CCWin;
using BookModel;

namespace WinFromBook
{
    public partial class FrmBookState : CCSkinMain
    {
        public FrmBookState()
        {
            InitializeComponent();
        }
        #region 封装方法，字段，执行操作

        int PageNum = 1;//设置当前页
        int PageCount = 6;//设置每页显示
        int PageTotal;//总页数

        List<BookStateInfo> lbs = new BLL.BookStateInfoBLL().SelectBookStateInfo();
        List<BookStateInfo> lbs2 = new List<BookStateInfo>();
        #region 分页显示
        public void PageBookState(List<BookStateInfo> lbs3)
        {
            this.skinListView1.Items.Clear();
                if(lbs3.Count%PageCount!=0)
                     PageTotal = Convert.ToInt16((lbs.Count / PageCount)+1);
                else
                    PageTotal = Convert.ToInt16((lbs.Count / PageCount));

            var BooKstate = lbs3.Skip(PageCount * (PageNum-1)).Take(PageCount);
            foreach (var item in BooKstate)
            {
                ListViewItem lvi = new ListViewItem(item.BookStateID + "");
                lvi.SubItems.Add(item.BID + "");
                lvi.SubItems.Add(item.Bname);
                lvi.SubItems.Add(item.BookState);
                lvi.SubItems.Add(item.remark);
                this.skinListView1.Items.Add(lvi);
            }
            this.skinLabel1.Text = "当前第" + PageNum + "页,共" + PageTotal + "页";
        }
        #endregion
        //查询状态操作
        public void GetState()
        {
            if (String.IsNullOrEmpty(this.textBookState.Text.Trim()))
            {
                PageBookState(lbs);
            }
            else
            {
                lbs2 = (from p in lbs where p.BookState.Contains(this.textBookState.Text) select p).ToList();
                if (lbs2.Count != 0)
                {
                    PageBookState(lbs2);
                }
                else
                {
                    MessageBox.Show("查询不到数据", "系统提示");
                    PageBookState(lbs);
                }

            }
        }
        #endregion
        private void FrmBookState_Load(object sender, EventArgs e)
        {
            PageBookState(lbs);
        }

        private void skinbtnCheckSee_Click(object sender, EventArgs e)
        {
            GetState();
        }

        private void skinbtnHomePage_Click(object sender, EventArgs e)
        {
            if (PageNum == 1)
            {
                MessageBox.Show("已经是首页了", "系统提示");
                return;
            }
            {
                PageNum = 1;

                if (lbs2.Count != 0)
                    PageBookState(lbs2);
                else
                    PageBookState(lbs);
            }
           
        }

        private void skinbtnPreviousPage_Click(object sender, EventArgs e)
        {
            if (PageNum == 1)
            {
                MessageBox.Show("已经是首页了", "系统提示");
                return;
            }
            PageNum--;
            if (lbs2.Count != 0)
                PageBookState(lbs2);
            else
                PageBookState(lbs);
        }

        private void skinbtnNextPage_Click(object sender, EventArgs e)
        {
            if (PageNum == PageTotal)
            {
                MessageBox.Show("已经是最后一页了", "系统提示");
                return;
            }
            PageNum++;
            if (lbs2.Count != 0)
                PageBookState(lbs2);
            else
                PageBookState(lbs);
        }

        private void skinbtnLastPage_Click(object sender, EventArgs e)
        {
            if (PageNum == PageTotal)
            {
                MessageBox.Show("已经是最后一页了", "系统提示");
                return;
            }
            else
            {
                PageNum = PageTotal;
                if (lbs2.Count != 0)
                    PageBookState(lbs2);
                else
                    PageBookState(lbs);
            }
          

        }
    }
}
